/**
 * Simple non-persistent database implementation
 * 
 * @author manel
 * 
 */

 dotDb = function() {

	this.tables = {};
}


$.extend(dotDb.prototype, {
	table: function() {
		this.dots = {};
		this.nDots = 0;
		this.keys = {};
	},
	createTable: function(name) {
		this.tables[name] = new this.table;
	},
	declareKey: function(table,keyName){
		this.tables[table].keys[keyName] = {};
	},
	insert: function(table,obj){
		this.tables[table].dots[this.tables[table].nDots] = obj;
		this.tables[table].nDots++;
		return this.tables[table].nDots - 1;
	},
	remove: function(table,n){
		delete this.tables[table].dots[n];
		this.tables[table].nDots--;
		return n;
	},
	filter: function(table, fn, that) {
		var t = this.tables[table];
		
		var completed = true;
		
		if (typeof that == "undefined") {
			that = this.tables.table;
		} 
		
		for (var k in t.dots) {
			if (!fn.call(that, t.dots[k])) {
				completed = false;
				break;	
			}
		}
		
		return completed;
	}
});
